﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sunny.Controls
{
	public class TableCell : System.Windows.Controls.Label
	{
		//protected System.Windows.Controls.Grid CellsContainer
		//{
		//    get
		//    {
		//        if (this.Parent == null)
		//            return null;
		//        return (System.Windows.Controls.Grid)this.Parent;
		//    }
		//}

		//protected System.Windows.Controls.Border Row
		//{
		//    get
		//    {
		//        if (this.CellsContainer == null)
		//            return null;
		//        return (System.Windows.Controls.Border)this.CellsContainer.Parent;
		//    }
		//}

		protected System.Windows.Controls.Grid Grid
		{
			get
			{
				return (System.Windows.Controls.Grid)this.Parent;
			}
		}

		/// <summary>
		/// The number of rows a cell should span.
		/// </summary>
		public int RowSpan
		{
			get
			{
				return System.Windows.Controls.Grid.GetRowSpan(this);
			}
			set
			{
				System.Windows.Controls.Grid.SetRowSpan(this, value);
			}
		}

		/// <summary>
		/// The number of columns a cell should span.
		/// </summary>
		public int ColumnSpan
		{
			get
			{
				return System.Windows.Controls.Grid.GetColumnSpan(this);
			}
			set
			{
				System.Windows.Controls.Grid.SetColumnSpan(this, value);
			}
		}

		public int RowIndex
		{
			get
			{
				return System.Windows.Controls.Grid.GetRow(this);
			}
			set
			{
				System.Windows.Controls.Grid.SetRow(this, value);
			}
		}

		public int ColumnIndex
		{
			get
			{
				return System.Windows.Controls.Grid.GetColumn(this);
			}
			set
			{
				System.Windows.Controls.Grid.SetColumn(this, value);
			}
		}

		public TableRow Row { get;internal set; }

		//public int AdditionalColumnIndex;

		public TableCell()
		{
			//DefaultStyleKeyProperty.OverrideMetadata(typeof(TableCell), new System.Windows.FrameworkPropertyMetadata(typeof(TableCell)));
			//this.BorderBrush = System.Windows.Media.Brushes.Black;
			//this.BorderThickness = new System.Windows.Thickness(0, 0, 1, 1);
		}

		protected override void OnVisualParentChanged(System.Windows.DependencyObject oldParent)
		{
			if (this.Style == null)
				this.Style = (System.Windows.Style)this.FindResource("TableCellsDefaultStyle");

			base.OnVisualParentChanged(oldParent);
		}
	}
}